package com.qys.livesMall.product.controller.sys;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qys.livesMall.common.result.R;
import com.qys.livesMall.product.entity.H2ProductGoodsinfo;
import com.qys.livesMall.product.entity.H2ProductProduct;
import com.qys.livesMall.product.service.H2ProductGoodsinfoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 *  商品模块
 * @author gmx
 * @since 2023-05-17
 */
@RestController
@Tag(name = "商品管理", description = "商品管理")
@RequestMapping("/h2-shop-goodsinfo")
@Validated
public class H2ProductGoodsinfoController {
    @Resource
    private H2ProductGoodsinfoService spuService;

    /***
     * 根据商品id查询
     */
    @GetMapping("/prdouct/{goodId}")
    @Operation(summary = "根据商品id查询")
    public R<H2ProductProduct> product(@PathVariable Long goodId){
        return spuService.product(goodId);
    }

    /***
     * 添加商品
     */
    @PostMapping(value = "/add")
    @Operation(summary = "添加商品")
    public R<Long> add(@Valid @RequestBody H2ProductProduct product){
        return spuService.saveProduct(product);
    }

    /***
     * 商品修改
     */
    @PostMapping(value = "/upd")
    @Operation(summary = "修改商品")
    public R upd(@Valid @RequestBody H2ProductProduct product){
        spuService.upd(product);
        return R.ok();
    }

    /***
     * 商品分页查询
     */
    @PostMapping("/page")
    public R<IPage<H2ProductGoodsinfo>> pageList(@RequestBody Page<H2ProductGoodsinfo> page){
        R<IPage<H2ProductGoodsinfo>> res = spuService.listPageByCatid(page);
        return res;
    }
    /***
     * 商品删除
     */
    @DeleteMapping("/{id}")
    public R delete(@PathVariable Long id){

        return spuService.delete(id);
    }
    /***
     * 商品下架
     */
    @PutMapping("/{id}")
    public R marketable(@PathVariable Long id){

        return spuService.marketable(id);
    }
}
